
-- By Chris Mackey

--pieces
local base = piece "base"
local stop = piece "stop"
local arm = piece "arm"
local twisty = piece "twisty"
local firept = piece "firept"
local l_strut = piece "l_strut"
local r_strut = piece "r_strut"
local lf_wheel = piece "lf_wheel"
local lb_wheel = piece "lb_wheel"
local rf_wheel = piece "rf_wheel"
local rb_wheel = piece "rb_wheel"

--variables
local aim = 1

function script.Create()
	Turn( firept, x_axis, 90 )
end

function script.StartMoving()
	Spin( lf_wheel, x_axis, 2 )
	Spin( lb_wheel, x_axis, 2 )
	Spin( rf_wheel, x_axis, 2 )
	Spin( rb_wheel, x_axis, 2 )
	--StartThread( Walk )
end

function script.StopMoving()
	StopSpin( lf_wheel, x_axis )
	StopSpin( lb_wheel, x_axis )
	StopSpin( rf_wheel, x_axis )
	StopSpin( rb_wheel, x_axis )
	--StartThread( StopWalk )
end

function script.QueryWeapon1() return firept end

function script.AimFromWeapon1() return base end

function script.AimWeapon1( heading, pitch )
	Signal( aim )
	SetSignalMask( aim )
	WaitForTurn( arm, x_axis )
	Turn( base, y_axis, heading, .5 )
	return true
end

function script.FireWeapon1()
	--swing anim
	Turn( arm, x_axis, 1, 10 )
	WaitForTurn( arm, x_axis )
	Turn( base, x_axis, .1, 6 )
	Sleep( 100 )
	Turn( base, x_axis, 0, 1 )
	Sleep( 1500 )
	Turn( arm, x_axis, 0, 1 )
	WaitForTurn( arm, x_axis )
end

function script.Killed()
	Explode( l_strut, SFX.EXPLODE )
	Explode( r_strut, SFX.EXPLODE )
	Explode( lf_wheel, SFX.EXPLODE )
	Explode( lb_wheel, SFX.EXPLODE )
	Explode( rf_wheel, SFX.EXPLODE )
	Explode( rb_wheel, SFX.EXPLODE )
	Explode( base, SFX.EXPLODE )
	Explode( arm, SFX.EXPLODE )
	Explode( stop, SFX.EXPLODE )
	
end
